package com.example.controller;

import com.example.DTO.FLTaskResultDTO;
import com.example.common.Result;
import com.example.entity.FLTrainingRound;
import com.example.service.FLTrainingRoundService;
import com.example.service.helper.FLTrainingRoundConverter;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * ClassName: FLTrainingRoundMapper.xml
 * Package: com.example.controller
 * Description:
 *
 * @Author achb
 * @Create 2025/3/30 17:12
 * @Version 1.0
 */
@RestController
@RequestMapping("/fltr")
public class FLTrainingRoundController {
    @Autowired
    private FLTrainingRoundService roundService;

    @PostMapping("/upload-result")
    public ResponseEntity<Result> uploadResult(@RequestBody FLTaskResultDTO taskResult) {
        List<FLTrainingRound> rounds = FLTrainingRoundConverter.convertFromTaskResult(taskResult);
        boolean insertSuccess = roundService.batchInsert(rounds);

        if (insertSuccess) {
            return ResponseEntity.ok(Result.success("结果上传成功"));
        } else {
            return ResponseEntity.status(HttpStatus.INTERNAL_SERVER_ERROR)
                    .body(Result.error("500", "结果上传失败"));
        }
    }

}